<template>
  <div class="frequent-contacts">
    <van-nav-bar
      left-arrow
      class="title-bar"
      title="常用联系人"
      :border="false"
      @click-left="$router.go(-1)"
    />
    <div class="seek" @click="$router.push('/communicate')">
      <i class="iconfont iconfangdajing"></i>
      请输入您想搜索的内容
    </div>
    <div
      class="box-text"
      v-for="(item, index) in suggestions"
      :key="index"
      @click="selectName(item)"
    >
      <div class="box-img">{{ imgName[index] }}</div>
      <div class="box-div">
        <span class="box-title">{{ item.realName }}</span>
        <div class="box-content">
          <span>{{ item.phone }}</span
          ><span class="box-line">|</span><span></span>{{ item.orgName }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSearchSuggestions } from '@/api/serach'
export default {
  data() {
    return {
      suggestions: [], // 联想建议数据列表
      imgName: [],
      id: ''
    }
  },
  created() {
    this.infoList()
    this.id = this.$route.params.id
  },
  mounted() {},
  methods: {
    async infoList() {
      const Q = {
        pageNumber: 1,
        pageSize: 5
      }
      try {
        const { data: res } = await getSearchSuggestions(Q)
        this.suggestions = res.data.records
        console.log(this.suggestions)
        this.imgName = this.suggestions.map(item => item.realName.split('')[0])
      } catch (error) {
        console.log(error)
      }
    },
    // 联系人点击
    selectName(item) {
      if (this.id === '1') {
        this.$router.push({ name: 'enterprises-signed', params: item })
      } else if (this.id === '2') {
        this.$router.push({ name: 'send-a-duplicate', params: item })
      } else if (this.id === '3') {
        this.$router.push({ name: 'add-enterprise', params: item })
      } else if (this.id === '4') {
        this.$router.push({ name: 'add-personal', params: item })
      }
    }
  }
}
</script>

<style scoped lang="less">
.frequent-contacts {
  .title-bar {
    height: 128px;
    width: 100%;
    padding-top: 40px;
    box-sizing: border-box;
    /deep/.van-nav-bar__title {
      font-size: 34px;
      font-weight: bold;
    }
    /deep/.van-icon {
      font-size: 48px;
      color: #000;
    }
  }
  .seek {
    width: 670px;
    height: 80px;
    margin-left: 40px;
    margin-top: 8px;
    background-color: #efeff4;
    font-size: 28px;
    color: #888888;
    line-height: 80px;
    text-align: center;
    border-radius: 8px;
    i {
      font-size: 30px;
      margin-right: 8px;
    }
  }
  .box-text {
    height: 156px;
    margin-left: 40px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e5e5e5;
    .box-img {
      height: 64px;
      width: 64px;
      line-height: 64px;
      text-align: center;
      margin-right: 27px;
      border-radius: 50%;
      background-color: #2489f2;
      color: #fff;
      font-size: 28px;
    }
    .box-div {
      .box-title {
        font-size: 30px;
        color: #101010;
      }
      /deep/.active {
        color: #2289f2;
      }
      .box-content {
        margin-top: 13px;
        font-size: 24px;
        color: #888888;
        .box-line {
          margin: 0 20px;
        }
      }
    }
  }
}
</style>
